# plugs/cc.py
#
#

""" set/get the control character """

__copyright__ = 'this file is in the public domain'

from ommbot.world import add_cmnd, add_example

def handle_cc(bot, ievent):
    """ cc [<controlchar>] .. set/get control character of channel """
    chan = ievent.channel
    try:
        what = ievent.args[0]
        if not bot.users.allowed(ievent.userhost, 'OPER'):
            return
        if len(what) > 1:
            ievent.reply("only one character is allowed")
            return
        bot.state.set(chan,'cc',what)
        bot.state.save()
        ievent.reply('control char set to %s' % what)
    except IndexError:
        # no argument given .. show cc of channel command is given in
        cchar = bot.state.get(chan,'cc')
        if cchar:
            ievent.reply('control character for channel %s is %s' % \
                             (chan,cchar))
        else:
            ievent.reply("default cc is !")

add_cmnd('cc', handle_cc, 'USER')
add_example('cc', 'set control char of channel or show control char of \
                channel','1) cc # 2) cc')
